﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Job.Web.Framework;
using Job.Entity;
using Job.Logic.Personal;

namespace Job.Web.userControls.Personal
{
    public partial class ResumeCenter : BaseCtrl
    {
        private int personAccountId
        {
            get
            {
                //后台管理员能通过后台为企业增加职位，所以在此处需要兼职企业ID从url或从Session中获取
                MySession session = new MySession();
                SessionPersonal sPerson = session.GetPersonalFromSession();
                if (null == sPerson)
                    return 0;
                else
                    return sPerson.PersonAccountid;
            }
        }

        PersonalLogic pl = new PersonalLogic();

        protected void Page_Load(object sender, EventArgs e)
        {
            this.LoadData();
        }

        private void LoadData()
        {
            
            IList<ResumeList> list = pl.GetResumeList(personAccountId);
            dvResume.DataSource = list;
            dvResume.DataBind();
        }

        protected void dvResume_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblID = (Label)e.Row.FindControl("lblid");
                Label lblSetid = (Label)e.Row.FindControl("lblSetid");
                Label lblSetName = (Label)e.Row.FindControl("lblSetName");
                int setid = Convert.ToInt32(lblSetid.Text.Trim());
                if (setid == 0)
                {
                    lblSetName.Text = "完全公开";
                }
                else if (setid == 1)
                {
                    lblSetName.Text = "隐藏简历";
                }
                else if (setid == 2)
                {
                    lblSetName.Text = "隐藏电话";
                }
            }
        }

        protected void dvResume_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int id = Convert.ToInt32(e.CommandArgument);
            if (e.CommandName.ToLower() == "refresh")
            {
                //edit
                //string url = WebCommon.GetApplicationPath(Request) + "Person/PersonalResume.aspx?subjectid=" + this.subjectid + "&tranid=" + id;
                //Response.Redirect(url);
                pl.RefreshResume(id);
                Response.Redirect(this.Request.RawUrl);
            }
            else if (e.CommandName.ToLower() == "edit")
            {
                string url = WebCommon.GetApplicationPath(Request) + "Person/PersonalResume.aspx?categoryid=1&subjectid=1" + "&resumeid=" + id;
                //string url = WebCommon.GetApplicationPath(Request) + "Person/PersonalResume.aspx?subjectid=" + this.subjectid;
                Response.Redirect(url);
            }
        }

        protected void btnCreateResume_Click(object sender, EventArgs e)
        {
            string url = WebCommon.GetApplicationPath(Request) + "Person/PersonManager.aspx?categoryid=1&ctrlid=1";

            //string url = WebCommon.GetApplicationPath(Request) + "Person/PersonalResume.aspx?subjectid=" + this.subjectid;
            Response.Redirect(url);
        }
    }
}